package cn.com.inossem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.com.inossem.activity.R;
import cn.com.inossem.model.QueryProjectInfoBean;

public class JobsMessagesAdapter extends BaseAdapter {
	private Context mContext;
	private LayoutInflater mInflater;
	private List<QueryProjectInfoBean> messageInfo;

	public JobsMessagesAdapter(Context mContext,
	                           List<QueryProjectInfoBean> messageInfo) {
		super();
		this.mContext = mContext;
		this.messageInfo = messageInfo;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		// return messageInfo.size();
		return messageInfo.size();
	}

	@Override
	public QueryProjectInfoBean getItem(int arg0) {
		// return messageInfo.get(arg0);
		return messageInfo.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.site_jobs_list_item, null);
		}

		ImageView newpic = (ImageView) convertView.findViewById(R.id.newpic);
		if (getItem(position).newFlag.equals("1")) {
			newpic.setVisibility(View.VISIBLE);
		} else {
			newpic.setVisibility(View.GONE);
		}
		TextView jobname = (TextView) convertView.findViewById(R.id.jobname);
		jobname.setText(getItem(position).projectName);
		TextView releasedate = (TextView) convertView
				.findViewById(R.id.releasedate);
		System.out.print("getItem(position).releaseDate:"
				+ getItem(position).releaseDate);
		releasedate.setText(getItem(position).releaseDate);
		TextView positions = (TextView) convertView
				.findViewById(R.id.positions);
		positions.setText("职位：" + getItem(position).station);
		TextView projectIndustry = (TextView) convertView
				.findViewById(R.id.projectIndustry);
		projectIndustry.setText("行业：" + getItem(position).projectIndustry);
		TextView modelRequire = (TextView) convertView
				.findViewById(R.id.modelRequire);
		modelRequire.setText("模块：" + getItem(position).modelRequire);

		TextView startDate = (TextView) convertView
				.findViewById(R.id.startDate);
		if (!getItem(position).startDate.equals(""))
			startDate.setText(getItem(position).startDate + " 开始");
		else
			startDate.setText("");

		TextView projectCycle = (TextView) convertView
				.findViewById(R.id.projectCycle);
		TextView projectCycleend = (TextView) convertView
				.findViewById(R.id.projectCycleend);

		if (getItem(position).projectCycle.contains("个月")) {
			projectCycle.setText(getItem(position).projectCycle.replace("个月", ""));
			projectCycleend.setVisibility(View.VISIBLE);
		} else if (getItem(position).projectCycle.equals("-99")) {
			projectCycle.setText("入职");
			projectCycleend.setVisibility(View.GONE);
		} else {
			projectCycle.setText(getItem(position).projectCycle);
			projectCycleend.setVisibility(View.VISIBLE);
		}
		TextView projectAddress = (TextView) convertView.findViewById(R.id.projectAddress);
		projectAddress.setText(getItem(position).projectAddress);
		return convertView;
	}
}
